﻿using System.Collections.Generic;

namespace WPFEdit.Util
{
    public static class Extension
    {
        public static void Move<TSource>(this IList<TSource> list, int oldIndex, int newIndex)
        {
            if (list.Count < 2) return;
            if (newIndex > oldIndex)
            {
                TSource temp = list[oldIndex];
                for (int i = oldIndex; i < newIndex; i++)
                {
                    list[i] = list[i+1];
                }
                list[newIndex] = temp;
            }
            else //newIndex > oldIndex
            {
                TSource temp = list[oldIndex];
                for (int i = oldIndex; i > newIndex; i--)
                {
                    list[i] = list[i-1];
                }
                list[newIndex] = temp;
            }
        }
    }
}
